home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
-
- #include <aux.h>
- #include <auxPrivate.h>
-
-
- /*************************************************************************
- * Toolkit Global variables
- **************************************************************************/
-
- GLboolean animation = AUX_OFF;
- GLboolean redrawRequired = GL_FALSE;
-
- static GLvoid DefaultReshape( GLsizei, GLsizei );
-
- GLvoid (*displayFunc)( GLvoid ) = NULL;
- GLvoid (*reshapeFunc)( GLsizei, GLsizei ) = DefaultReshape;
- GLvoid (*idleFunc)( GLvoid ) = NULL;
- GLvoid (*exposeFunc)( GLsizei, GLsizei ) = NULL;
-
-
-
- /**************************************************************************
- * auxDispatchEvent()
- **************************************************************************/
-
- GLvoid
- auxDispatchEvent( GLint device )
- {
- GLsizei width, height;
-
- AUX_EVENTREC auxEvent;
-
- switch ( device ) {
-
- case AUX_CONFIG :
- #ifdef DEBUG2
- printf(" Toolkit : Calling reshapeFunc() ...\n");
- #endif
- auxGetSize( &width, &height );
- (*reshapeFunc)( width, height );
- redrawRequired = GL_TRUE;
- break;
-
- case AUX_EXPOSE :
- #ifdef DEBUG2
- printf(" Toolkit : Calling exposeFunc() ...\n");
- #endif
- auxGetSize( &width, &height );
- if (exposeFunc)
- {
- (*exposeFunc)( width, height );
- }
- redrawRequired = GL_TRUE;
- break;
-
- case AUX_DRAW :
- redrawRequired = GL_TRUE;
- break;
-
- case AUX_LEFTBUTTON :
- case AUX_MIDDLEBUTTON :
- case AUX_RIGHTBUTTON :
- #ifdef DEBUG2
- printf(" Toolkit : Calling mouse functions ...\n");
- #endif
- auxEvent.data[AUX_MOUSEX] = auxMouseX;
- auxEvent.data[AUX_MOUSEY] = auxMouseY;
-
- { MouseFunc *tmp;
-
- if ( auxValue ) {
- auxEvent.event = AUX_MOUSEDOWN;
- tmp = mouseDown[device - AUX_BUTTON_MASK];
- } else {
- auxEvent.event = AUX_MOUSEUP;
- tmp = mouseUp[device - AUX_BUTTON_MASK];
- }
-
- if ( tmp ) {
- redrawRequired = GL_TRUE;
- while ( tmp ) {
- (*tmp->func)( &auxEvent );
- tmp = tmp->next;
- }
- }
- } break;
-
- case AUX_MOUSELOC : {
- MouseFunc *tmp = mouseLoc;
-
- auxEvent.event = AUX_MOUSELOC;
- auxEvent.data[AUX_MOUSEX] = auxMouseX;
- auxEvent.data[AUX_MOUSEY] = auxMouseY;
- if ( tmp ) {
- #ifdef DEBUG2
- printf(" Toolkit : Calling mouseLoc() ...\n");
- #endif
- redrawRequired = GL_TRUE;
- while ( tmp ) {
- (*tmp->func)( &auxEvent );
- tmp = tmp->next;
- }
- }
- } break;
-
- case AUX_KEYEVENT : {
- KeyFunc *tmp = keyHead;
-
- if ( !auxValue )
- return;
-
- while ( tmp )
- if ( auxDevice == tmp->key ) {
- #ifdef DEBUG2
- printf(" Toolkit : Calling KeyFunc() ...\n");
- #endif
- (*tmp->keyFunc)();
- redrawRequired = GL_TRUE;
- break;
- } else if ( auxDevice < tmp->key )
- tmp = tmp->right;
- else
- tmp = tmp->left;
- } break;
-
- default :
- #ifdef DEBUG2
- printf(" Toolkit : Default Event case ...\n");
- #endif
- break;
- }
- }
-
-
- /**************************************************************************
- * auxMainLoop() - set display function pointer
- **************************************************************************/
-
- GLvoid
- auxMainLoop( GLvoid (*_displayFunc)( GLvoid ) )
- {
- GLint device, value, mousex, mousey;
-
- displayFunc = _displayFunc;
-
- while ( GL_TRUE ) {
- while ( auxEventPending() ||
- ( animation == AUX_OFF && !redrawRequired && !idleFunc ) ) {
- device = auxReadEvent( &value, &mousex, &mousey );
-
- if ( !(( device >= AUX_EXPOSE && device <= AUX_INPUTCHANGE ) ||
- ( device >= AUX_LEFTBUTTON && device <= AUX_RIGHTBUTTON ) ||
- ( device >= AUX_SHIFT && device <= AUX_ALT ) ||
- device == AUX_NOEVENT) )
- device = AUX_KEYEVENT;
-
- auxDispatchEvent( device );
- }
-
- if ( animation || redrawRequired ) {
- (*displayFunc)();
- redrawRequired = GL_FALSE;
- }
- if ( idleFunc ) {
- (*idleFunc)();
- }
- }
- }
-
-
- /**************************************************************************
- * auxReshapeFunc() - set reshape function pointer
- **************************************************************************/
-
- GLvoid
- auxReshapeFunc( GLvoid (*_reshapeFunc)( GLsizei, GLsizei ) )
- {
- reshapeFunc = _reshapeFunc;
- }
-
- /**************************************************************************
- * auxExposeFunc() - set expose function pointer
- * Provided for compatibility with OpenGL Programming Guide libaux
- **************************************************************************/
-
- GLvoid
- auxExposeFunc( GLvoid (*_exposeFunc)( GLsizei, GLsizei ) )
- {
- exposeFunc = _exposeFunc;
- }
-
- /**************************************************************************
- * auxIdleFunc() - set idle function pointer
- * Provided for compatibility with OpenGL Programming Guide libaux
- * For animation of displayFunc, use auxAnimation() instead.
- **************************************************************************/
-
- GLvoid
- auxIdleFunc( GLvoid (*_idleFunc)( GLvoid ) )
- {
- idleFunc = _idleFunc;
- }
-
-
-
- /**************************************************************************
- * auxAnimation() - set animation function callback
- **************************************************************************/
-
- GLvoid
- auxAnimation( GLboolean state )
- {
- animation = state;
- }
-
-
- /**************************************************************************
- * DefaultReshape() - Default Internal Reshape Function
- **************************************************************************/
-
- static GLvoid
- DefaultReshape( GLsizei width, GLsizei height )
- {
- GLint matrixMode;
-
- glViewport( 0, 0, width, height );
- glGetIntegerv( GL_MATRIX_MODE, &matrixMode );
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- glOrtho( -0.5, (GLfloat) width-0.5, -0.5, (GLfloat) height-0.5, -1.0, 1.0 );
- glMatrixMode( matrixMode );
- }
-